package com.slfx.function.permission.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * <p>集合拷贝</p>
 *
 * @author huanglingbin
 */
public class BeanCopyUtil extends BeanUtils {

    /**
     * 集合数据的拷贝
     *
     * @param sources 源数据
     * @param target  目标类::new(eg: MaterialBorrowRecordDetail::new)
     * @return
     */
    public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target) {
        if (sources == null || target == null) {
            return null;
        }
        List<T> list = new ArrayList<>();
        sources.forEach(v -> {
            T t = target.get();
            copyProperties(v, t);
            list.add(t);
        });
        return list;
    }

}
